Skip to content

Order the roots of polynomials with particle coefficients consistently - #1103

Open
baggepinnen wants to merge 1 commit into
masterfrom
fb/particle-roots-ordering
Open

baggepinnen wants to merge 1 commit into
masterfrom
fb/particle-roots-ordering

Conversation

@baggepinnen

Copy link
Copy Markdown
Member

Fixes the zpk conversion failure reported in JuliaControl/RobustAndOptimalControl.jl#118.

ControlSystemsBase.roots calls Polynomials.roots(p; sortby=nothing). For a polynomial with MonteCarloMeasurements particle coefficients, the eigenvalues of the companion matrix are computed for each particle separately, and without sorting, the order returned by LAPACK differs between particles. A particle-valued root then combines different roots (in the example of the issue, the first root is real in 1493 particles and complex in 507), so the particle-valued roots do not form exact conjugate pairs and SisoZpk throws zpk model should be real-valued, but poles do not come in conjugate pairs.

Changes:

  • Add the package extension ControlSystemsBaseMonteCarloMeasurementsExt, in which roots of a polynomial with AbstractParticles coefficients uses the default sorting by real and imaginary part. The members of each conjugate pair then occupy the same adjacent positions in every particle. The order of roots for other coefficient types is unchanged.
  • Add a test with the example from the issue, run after all other tests since MonteCarloMeasurements depends on GenericSchur, which the tests in runtests.jl and test_analysis.jl require to be unloaded initially.

The full ControlSystemsBase test suite passes locally (Julia 1.13.2).

Not addressed here:

  • bodeplot of the uncertain zpk or ss model fails on comparisons of uncertain values unless unsafe_comparisons(true) is set.
  • With only ControlSystemsBase and MonteCarloMeasurements loaded, poles of an uncertain tf (used by bodeplot) fails on a method ambiguity of \ between MonteCarloMeasurements and LinearAlgebra in MatrixPencils.poldiv. With RobustAndOptimalControl loaded, bodeplot of the uncertain tf works.

Host: demeter2, session: MatrixEquations v3 compat PRs (session_01JGy8YZaumSKXZ3ucgmVARB), working directory: /home/baggepinnen/.julia/dev

🤖 Generated with Claude Code

The roots of a polynomial with MonteCarloMeasurements particle coefficients
are computed for each particle separately. Without sorting, the order of
the roots differs between particles, so the particle-valued roots do not
form conjugate pairs and the conversion to zpk fails. A package extension
computes these roots with the default sorting by real and imaginary part.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuliaControlBot

Copy link
Copy Markdown

This is an automated message.
Plots were compared to references. 6/11 images have changed, see differences below.
After pulling this PR, please update the reference images by creating a PR to ControlExamplePlots.jl here.

Difference Reference Image New Image
✔️ 0.0 Reference New
⚠️ 0.021 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.013 Reference New

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.29%. Comparing base (6f28683) to head (62daeb8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1103   +/-   ##
=======================================
  Coverage   92.29%   92.29%           
=======================================
  Files          42       43    +1     
  Lines        6177     6179    +2     
=======================================
+ Hits         5701     5703    +2     
  Misses        476      476           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants